//
//  RegisterViewController.m
//  TravelDiary
//
//  Created by lanou3g on 15/11/12.
//  Copyright © 2015年 YDB MAC. All rights reserved.
//

#import "RegisterViewController.h"
#import <AVOSCloud.h>
#import "LoginViewController.h"
@interface RegisterViewController ()
@property (strong, nonatomic) IBOutlet UITextField *userNmae;
@property (strong, nonatomic) IBOutlet UITextField *PassWord;
@property (strong, nonatomic) IBOutlet UITextField *Emeil;


@end

@implementation RegisterViewController

- (void)viewDidLoad {
    
    UIImageView *left = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconfont-fangqiuzhiyepeiyangzhuanhuan"]];
    self.userNmae.leftView = left;
    self.userNmae.leftViewMode = UITextFieldViewModeAlways;
    
    UIImageView *left2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconfont-mima"]];
    self.PassWord.leftView = left2;
    self.PassWord.leftViewMode = UITextFieldViewModeAlways;
    
    UIImageView *left3 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconfont-wbdiconemail"]];
    self.Emeil.leftView = left3;
    self.Emeil.leftViewMode = UITextFieldViewModeAlways;
    
    [super viewDidLoad];
}

- (IBAction)RegisterButton:(id)sender {
 
    AVUser * user = [AVUser user];
    user.password = _PassWord.text;
    user.email = self.Emeil.text ;
    user.username = self.userNmae.text ;
    [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            self.myNameBlock(self.userNmae.text);
            LoginViewController *loginVc = [[LoginViewController alloc]init];
            [self.navigationController pushViewController:loginVc animated:YES];
        }else
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"注册失败" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            }];
            [alert addAction:action];
            [self presentViewController:alert animated:YES completion:nil];
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
